package com.xiaofei.Tools;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Date;
import java.util.Map;
public class JwtUtil {

    private static final String key = "xiaofei";
    private static final long time = 12*3600*1000;
    public static String createJwt(Map<String,Object> claims){
        return Jwts.builder()
                .setClaims(claims)//设置用户信息
                .setExpiration(new Date(System.currentTimeMillis()+time))//设置过期时间
                .signWith(SignatureAlgorithm.HS256, key)//设置加密算法和密钥
                .compact();
    }
    public static Claims parseClaims(String jwt){
        return Jwts.parser()
                .setSigningKey(key)//设置密钥
                .parseClaimsJws(jwt)//解析jwt
                .getBody();//获取用户信息
    }
}








